package com.contentprovider;

import android.app.Activity;
import android.content.ContentResolver;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.CallLog.Calls;
import android.widget.TextView;

public class ContentProviderActivity extends Activity {

	ContentResolver cr;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		cr = getContentResolver();
		Uri uri = Calls.CONTENT_URI;
		query(uri);

	}

	private void query(Uri uri) {
		String[] projection = new String[] { Calls.TYPE, Calls.NUMBER };
		Cursor c = cr.query(uri, projection, null, null, null);
		int typeColumn = c.getColumnIndex(Calls.TYPE);
		int numberColumn = c.getColumnIndex(Calls.NUMBER);
		TextView tv = (TextView) findViewById(R.id.textView1);
		tv.setText("");
		while (c.moveToNext()) {
			String type = "";
			tv.append(typeColumn + " - " + c.getString(numberColumn) + "\n");
		}

	}

}